#include <Windows.h>
#include <tchar.h>
#include "resource.h"

int CALLBACK DlgProc(HWND hDlg, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
	switch (nMsg)
	{
		case WM_INITDIALOG:
		{
			SetWindowText(hDlg, _T("Demo0104"));

			UINT nWidth		= GetSystemMetrics(SM_CXSCREEN);
			UINT nHeight	= GetSystemMetrics(SM_CYSCREEN);
			RECT rtClient;
			GetClientRect(hDlg, &rtClient);
			SetWindowPos(hDlg, NULL, (nWidth - (rtClient.right - rtClient.left)) / 2, (nHeight - (rtClient.bottom - rtClient.top)) / 2, 0, 0, SWP_NOSIZE);
			
			if (!RegisterHotKey(hDlg, 0xC002, MOD_ALT|MOD_CONTROL, _T('A')))
			{
				MessageBox(hDlg, _T("CTRL + ALT + A is registered"), _T("Demo0104"), MB_OK);
			}
			if (!RegisterHotKey(hDlg, 0xC001, MOD_CONTROL, 0X5A))
			{
				MessageBox(hDlg, _T("CTRL + Z is registered"), _T("Demo0104"), MB_OK);
			}
			if (!RegisterHotKey(hDlg, GlobalAddAtom(_T("0xC000")), 0, VK_F3))
			{
				MessageBox(hDlg, _T("F3 is registered"), _T("Demo0104"), MB_OK);
			}
								
			break;
		}
		case WM_HOTKEY:
		{
 			if (HIWORD(lParam) == _T('A') && LOWORD(lParam) == MOD_CONTROL|MOD_ALT)
			{
 				ShowWindow(hDlg, SW_HIDE);
 			}
			if (HIWORD(lParam) == 0X5A && LOWORD(lParam) == MOD_CONTROL)
			{
				ShowWindow(hDlg, SW_SHOW);
				SetForegroundWindow(hDlg);
			}
			if (HIWORD(lParam) == VK_F3)
			{
				EndDialog(hDlg, 0);
			}
			
			break;
		}
		case WM_COMMAND:
		{
			break;
		}
		case WM_CLOSE:
		{
			EndDialog(hDlg, 0);
			break;
		}
		case WM_DESTROY:
		{
			UnregisterHotKey(hDlg, _T('A'));
			UnregisterHotKey(hDlg, 0x5A);
			UnregisterHotKey(hDlg, VK_F3);
			

			PostQuitMessage(0);
			break;
		}
	}

	return 0;
}

BOOL WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPreInstance, LPTSTR szCmdLine, int nShowCmd)
{
	DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG), NULL, DlgProc);

	return TRUE;
}